﻿Imports System.Text
Imports System.IO

Public Class w0003
    Dim duoma As String = ""
    Private Sub w0003_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim tmps As String = ""

        For i = 0 To 9
            For j = i + 1 To 9
                For k = j + 1 To 9
                    For l = k + 1 To 9
                        tmps = i.ToString & j.ToString & k.ToString & l.ToString
                        ListBox1.Items.Add(tmps)
                    Next
                Next
            Next
        Next
        Label1.Text = ListBox1.Items.Count
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        '判断四码出三的遗漏情况
        Dim tmpS As String = ""
        Dim tmpBool As Boolean = False
        Dim tx As Integer = 0, ty As Integer = 0
        Dim sb As New StringBuilder

        ' tmpS = ListBox1.Items(i).ToString '
        For w = 0 To general_Ubound
            tmpBool = pd_n_chu_m(duoma, arrJH_S(w), 3)
            If tmpBool = False Then
                    tx = tx + 1
                Else
                    sb.Append(arrQH(w) & vbTab & arrJH_S(w) & vbTab & tx.ToString & vbCrLf)
                    tx = 0
                    ty = ty + 1
                End If
            Next

        TextBox1.Text = sb.ToString
        Label2.Text = ty.ToString
    End Sub
    Function pd_n_chu_m(n As String, m As String, chushu As Integer) As Boolean
        'n为给定的胆码
        'm为开奖号码
        Dim mX As String = del_duplicate(m)
        Dim flagBool As Boolean = False
        Dim t1 As String = "", t2 As String = ""
        Dim t As Integer = 0
        For i = 0 To n.Length - 1
            t1 = n.Substring(i, 1)
            If mX.IndexOf(t1) >= 0 Then
                t = t + 1
            End If
        Next
        If t = chushu Then
            Return True
        Else
            Return False
        End If
    End Function
    Function del_duplicate(str As String) As String
        Dim tmps As String = str.Substring(0, 1)
        Dim x As String = ""
        For i = 1 To str.Length - 1
            x = str.Substring(i, 1)
            If tmps.IndexOf(x) < 0 Then
                tmps = tmps & x
            End If
        Next
        Return tmps
    End Function

    Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
        duoma = ListBox1.SelectedItem.ToString
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim tmpS As String = "", tmps1 As String = ""
        Dim tx As String = ""
        Dim ty As Integer = 0
        Dim tz As Integer = 0
        Dim sb As New StringBuilder
        Dim geshu As Integer = CInt(TextBox3.Text)
        For i = 0 To 99999
            If i = 12345 Then
                Debug.Print("1")
            End If
            tmps1 = i.ToString.PadLeft(5, "0")
            tmpS = del_duplicate(tmps1)
            For j = 0 To tmpS.Length - 1
                tx = tmpS.Substring(j, 1)
                If duoma.IndexOf(tx) >= 0 Then
                    ty = ty + 1
                End If
            Next
            If ty >= geshu Then
                sb.Append(tmps1 & " "）
                tz = tz + 1
            End If
            ty = 0
        Next
        TextBox1.Text = sb.ToString.Trim
        Label2.Text = tz.ToString
    End Sub
End Class